//
//  YZXRetweetView.swift
//  YZXWeibo
//
//  Created by 叶周翔 on 16/7/25.
//  Copyright © 2016年 叶周翔. All rights reserved.
//

import UIKit

class YZXRetweetView: UIView {
    
    var retweetStatus:YZXStatus?{
        didSet {
            // 获取被转发的微博模型 设置内容
            if retweetStatus == nil {
                retweetContentLabel.text = "没有被转发的微博"
            }else{
              
                //被转发微博的内容
                retweetContentLabel.text = retweetStatus?.retweetString
            }
            // 设置配图
            retweetPicture.imageURLs = retweetStatus?.storePictureURLs
            
            // 判断是否有图片 有图片配图顶部到文字底部的间距为8 没有配图就为0
            retweetPicture.snp_updateConstraints { (make) -> Void in
                
                var margin:CGFloat = 0
                if retweetStatus?.storePictureURLs != nil && retweetStatus?.storePictureURLs?.count > 0{
                    margin = CellMargin
                }
                make.top.equalTo(retweetContentLabel.snp_bottom).offset(margin)
            }
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    private func setUpUI(){
        
        self.addSubview(retweetContentLabel)
        self.addSubview(retweetPicture)
        
        // 添加约束
        retweetContentLabel.snp_makeConstraints { (make) -> Void in
            make.leading.top.equalTo(self).offset(CellMargin)
        }
        
        // 被转发微博图片
        retweetPicture.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(CellMargin)
            make.top.equalTo(retweetContentLabel.snp_bottom).offset(CellMargin)
            make.size.equalTo(CGSize(width: 300, height: 300))
        }
        
        // 底部约束,被转发view的底部和配图的底部重合
        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(retweetPicture).offset(CellMargin)
        }
        
        
    }
    private lazy var retweetContentLabel:UILabel = {
       
        let label = UILabel(textColor: UIColor.darkGrayColor())
        
        // 设置换行的宽度
        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.size.width - 2 * CellMargin
        label.font = UIFont.systemFontOfSize(reweetFont)
        label.numberOfLines = 0
        return label
    }()
    
    lazy var retweetPicture:YZXPictureView = YZXPictureView()
    
    
}
